web/src/pages/[...listing].astro
504 lines · 14269 bytes
1---
2import Layout from '@layouts/Layout.astro';
3import ListingHero from '@components/things/ListingHero.astro';
4import ServiceList from '@components/things/ServiceList.astro';
5import Comments from '@components/things/Comments.svelte';
6import GitHubDetailedInfo from '@components/things/GitHubDetailedInfo.astro';
7import SecurityDetailedInfo from '@components/things/SecurityDetailedInfo.astro';
8import PrivacyPolicyDetails from '@components/things/PrivacyPolicyDetails.astro';
9import WebsiteDetailedInfo from '@components/things/WebsiteDetailedInfo.astro';
10import DockerDetailedInfo from '@components/things/DockerDetailedInfo.astro';
11import IosAppDetailedInfo from '@components/things/IosAppDetailedInfo.astro';
12import AndroidAppDetailedInfo from '@components/things/AndroidDetailedInfo.astro';
13import DiscordDetailedInfo from '@components/things/DiscordDetailedInfo.astro';
14import RedditDetailedInfo from '@components/things/RedditDetailedInfo.astro';
15import SocialShare from '@components/form/Social.astro';
16import DataActions from '@components/things/DataActions.svelte';
17import type { AwesomePrivacy, Section, Service } from '../types/Service';
18import { fetchData, slugify } from '@utils/fetch-data';
19import { fetchServiceSources } from '@utils/fetch-line-numbers';
20import { codebergUrl } from '@utils/parse-markdown';
21import { plainText, truncate } from '@utils/meta-tags';
22import { fetchChangelog } from '@utils/fetch-changelog';
23import { fetchGitHubStats } from '@utils/fetch-repo-info';
24import { fetchSecurityReport } from '@utils/fetch-security-info';
25import { fetchTosdrPrivacy } from '@utils/fetch-privacy-policy';
26import { fetchWebsiteInfo } from '@utils/fetch-website-info';
27import { fetchDockerData } from '@utils/fetch-docker-instructions';
28import { fetchIosInfo } from '@utils/fetch-ios-info';
29import { fetchAndroidInfo } from '@utils/fetch-android-info';
30import { fetchPlexusInfo } from '@utils/fetch-plexus-info';
31import { fetchDiscordInfo } from '@utils/fetch-discord-info';
32import { fetchRedditInfo } from '@utils/fetch-reddit-info';
33import { site } from '@utils/config';
34import { apiBase, serviceSlug } from '@utils/api-config';
35import Button from '@components/form/Button.astro';
36
37interface Props extends Service {
38 slug: string;
39 parentSection: Section;
40 categoryName: string;
41}
42
43const {
44 name,
45 description,
46 url,
47 github,
48 codeberg,
49 git,
50 tosdrId,
51 discordInvite,
52 subreddit,
53 iosApp,
54 androidApp,
55 parentSection,
56 categoryName,
57} = Astro.props;
58
59const makeKeyWordTag = () => {
60 const keywords = [
61 `open source ${parentSection.name}`,
62 `${parentSection.name} comparison`,
63 ...(parentSection.alternativeTo || []).map(
64 (alt: string) => `${alt} alternative`,
65 ),
66 ...(parentSection.services || []).map((serv: Service) => `${serv.name} vs`),
67 'private',
68 'ad free',
69 'encrypted',
70 'open source software',
71 'privacy respecting apps',
72 'free tools',
73 ];
74 return keywords.join(', ');
75};
76
77const makePageTitle = () => {
78 return `${name} | ${parentSection.name} | ${categoryName} | Awesome Privacy`;
79};
80
81const makeBreadcrumbs = () => {
82 return [
83 { name: 'Home', item: '/' },
84 { name: categoryName, item: slugify(categoryName) },
85 {
86 name: parentSection.name,
87 item: `${slugify(categoryName)}/${slugify(parentSection.name)}`,
88 },
89 {
90 name: name,
91 item: `${slugify(categoryName)}/${slugify(parentSection.name)}/${slugify(name)}`,
92 },
93 ];
94};
95
96const plainDescription = plainText(description);
97
98const makeDescriptionTag = () => {
99 const summary = `${name}: ${plainDescription}`.replace(/([^.!?])$/, '$1.');
100 if (summary.length >= 120) return truncate(summary);
101 return truncate(
102 `${summary} Compare it with other private ${parentSection.name.toLowerCase()} on Awesome Privacy.`,
103 );
104};
105
106const filterServices = () => {
107 return parentSection.services.filter((s: Service) => s.name !== name);
108};
109
110export async function getStaticPaths() {
111 const pages = await fetchData().then((data) => {
112 const results: Array<Props> = [];
113 if (!data || !data.categories) return results;
114 (data as AwesomePrivacy).categories.forEach((category) => {
115 category.sections.forEach((section) => {
116 const services = (section.services || []).map((service) => {
117 return {
118 slug: `${slugify(category.name)}/${slugify(section.name)}/${slugify(service.name)}`,
119 parentSection: section,
120 categoryName: category.name,
121 ...service,
122 };
123 });
124 results.push(...services);
125 });
126 });
127 return results;
128 });
129
130 return pages.map((props: Props) => {
131 return { params: { listing: props.slug }, props };
132 });
133}
134
135const makePaginationLinks = () => {
136 const allServices = parentSection.services || [];
137 const index = allServices.findIndex((item) => item.name === name);
138 const previousItem = index > 0 ? allServices[index - 1].name : null;
139 const nextItem =
140 index < allServices.length - 1 ? allServices[index + 1].name : null;
141 return { previous: previousItem, next: nextItem };
142};
143
144const { previous, next } = makePaginationLinks();
145
146const ignoredSites = ['github.com', 'wikipedia.'];
147
148const githubData = github ? await fetchGitHubStats(github) : null;
149const securityData = github ? await fetchSecurityReport(github) : null;
150const hasSecurityData =
151 !!securityData &&
152 ((securityData.scorecard.available &&
153 securityData.scorecard.checks.length > 0) ||
154 securityData.advisories.count > 0);
155const privacyData = tosdrId ? await fetchTosdrPrivacy(tosdrId) : null;
156const iosData = iosApp ? await fetchIosInfo(iosApp) : null;
157const androidData = androidApp ? await fetchAndroidInfo(androidApp) : null;
158const plexusData = androidApp ? await fetchPlexusInfo(androidApp) : null;
159const discordData = discordInvite
160 ? await fetchDiscordInfo(discordInvite)
161 : null;
162const redditData = subreddit ? await fetchRedditInfo(subreddit) : null;
163const dockerData = await fetchDockerData(name);
164const sources = await fetchServiceSources(categoryName, parentSection.name);
165const websiteData =
166 url && !ignoredSites.some((s) => url.includes(s))
167 ? await fetchWebsiteInfo(url)
168 : null;
169
170const serviceHistory = await fetchChangelog().then(({ entries }) => {
171 const isMatch = (c: { name: string; category: string; section: string }) =>
172 c.name === name &&
173 c.category === categoryName &&
174 c.section === parentSection.name;
175 const isHere = (m: {
176 name: string;
177 to: { category: string; section: string };
178 }) =>
179 m.name === name &&
180 m.to.category === categoryName &&
181 m.to.section === parentSection.name;
182 const results: Array<{
183 date: string;
184 type: 'added' | 'removed' | 'modified' | 'moved' | 'renamed';
185 fields?: string[];
186 from?: { category: string; section: string };
187 previousName?: string;
188 pr?: import('@utils/fetch-changelog').ChangelogPr | null;
189 }> = [];
190 for (const e of entries) {
191 const s = e.changes?.services;
192 const added = (s?.added || []).find(isMatch);
193 const removed = (s?.removed || []).find(isMatch);
194 const modified = (s?.modified || []).find(isMatch);
195 const moved = (s?.moved || []).find(isHere);
196 const renamed = (s?.renamed || []).find(isHere);
197 if (added) results.push({ date: e.date, type: 'added', pr: e.pr });
198 else if (removed) results.push({ date: e.date, type: 'removed', pr: e.pr });
199 else if (modified)
200 results.push({
201 date: e.date,
202 type: 'modified',
203 fields: modified.fields,
204 pr: e.pr,
205 });
206 else if (renamed)
207 results.push({
208 date: e.date,
209 type: 'renamed',
210 previousName: renamed.previousName,
211 from: renamed.from,
212 pr: e.pr,
213 });
214 else if (moved)
215 results.push({ date: e.date, type: 'moved', from: moved.from, pr: e.pr });
216 }
217 return results;
218});
219
220const findPrivacyPolicyLink = () => {
221 if (!privacyData) return null;
222 const docs = privacyData?.parameters?.documents;
223 if (docs) {
224 const pp = (docs || []).find((doc) =>
225 doc.name.toLowerCase().includes('privacy policy'),
226 );
227 if (pp) return pp.url;
228 }
229 return `https://tosdr.org/en/service/${tosdrId}`;
230};
231
232const privacyPolicyLink = findPrivacyPolicyLink();
233
234const catSlug = slugify(categoryName);
235const secSlug = slugify(parentSection.name);
236
237const getApiEndpoint = () => {
238 return `${apiBase}/v1/services/${serviceSlug(name)}`;
239};
240
241const makeSoftwareSchema = () => {
242 const operatingSystem = [
243 iosApp && 'iOS',
244 androidApp && 'Android',
245 url && 'Web',
246 ].filter(Boolean);
247 const codeRepository = github
248 ? `https://github.com/${github}`
249 : codeberg
250 ? codebergUrl(codeberg)
251 : git || null;
252 return {
253 '@context': 'https://schema.org',
254 '@type': 'SoftwareApplication',
255 name,
256 description: plainDescription || makeDescriptionTag(),
257 url,
258 applicationCategory: parentSection.name,
259 ...(operatingSystem.length && {
260 operatingSystem: operatingSystem.join(', '),
261 }),
262 ...(codeRepository && { codeRepository }),
263 };
264};
265---
266
267<Layout
268 title={makePageTitle()}
269 keywords={makeKeyWordTag()}
270 description={makeDescriptionTag()}
271 breadcrumbs={makeBreadcrumbs()}
272 customSchemaJson={makeSoftwareSchema()}
273>
274 <main>
275 <ListingHero
276 service={Astro.props}
277 parentSection={parentSection}
278 categoryName={categoryName}
279 privacyPolicyLink={privacyPolicyLink}
280 />
281 {
282 privacyData && privacyData.parameters?.points?.length > 0 && (
283 <section>
284 <h2>{name} Privacy Policy</h2>
285 <PrivacyPolicyDetails privacyData={privacyData} />
286 </section>
287 )
288 }
289 {
290 github && githubData && (
291 <section class="github-wrap">
292 <h2>{name} Source Code</h2>
293 <GitHubDetailedInfo gitHubData={githubData} repo={github} />
294 </section>
295 )
296 }
297 {
298 hasSecurityData && securityData && (
299 <section>
300 <h2>{name} Security</h2>
301 <SecurityDetailedInfo security={securityData} />
302 </section>
303 )
304 }
305 {
306 websiteData && (
307 <section>
308 <h2>{name} Website</h2>
309 <WebsiteDetailedInfo url={url} websiteInfo={websiteData} />
310 </section>
311 )
312 }
313 {
314 ((androidData && !androidData.error) || plexusData) && (
315 <section>
316 <h2>{name} Android App</h2>
317 <AndroidAppDetailedInfo
318 androidData={androidData}
319 plexusData={plexusData}
320 />
321 </section>
322 )
323 }
324 {
325 iosData &&
326 typeof iosData === 'object' &&
327 Object.keys(iosData).length > 0 && (
328 <section>
329 <h2>{name} iOS App</h2>
330 <IosAppDetailedInfo url={url} iosData={iosData} />
331 </section>
332 )
333 }
334 {
335 dockerData && dockerData.found && (
336 <section>
337 <h2>{name} Docker</h2>
338 <DockerDetailedInfo docker={dockerData} />
339 </section>
340 )
341 }
342 {
343 (discordData || redditData) && (
344 <section>
345 <h2>{name} Socials</h2>
346 <div class="social-wrap">
347 {discordData && <DiscordDetailedInfo discordData={discordData} />}
348 {redditData && <RedditDetailedInfo redditData={redditData} />}
349 </div>
350 </section>
351 )
352 }
353
354 <section>
355 <h2>{name} Reviews</h2>
356 <Comments client:visible />
357 </section>
358
359 <section>
360 <h2>More {parentSection.name}</h2>
361 <ServiceList
362 services={filterServices()}
363 subHeading={true}
364 noGitHubMetrics={true}
365 buttonLink={`/${catSlug}/${secSlug}/`}
366 categoryName={categoryName}
367 sectionName={parentSection.name}
368 />
369 </section>
370 <section>
371 <h2>About the Data: {name}</h2>
372 <DataActions
373 categoryName={categoryName}
374 sectionName={parentSection.name}
375 serviceName={name}
376 history={serviceHistory}
377 source={sources[name]}
378 />
379 <h3>API</h3>
380 <p>
381 You can access {name}'s data programmatically via our API. Simply make a <code
382 >GET</code
383 > request to:
384 </p>
385 <pre><a href={getApiEndpoint()}><code>{getApiEndpoint()}</code></a></pre>
386 <p>
387 The REST API is free, no-auth and CORS-enabled. To learn more, view the <a
388 href={`${apiBase}/docs`}>API Docs</a
389 > or read the <a href="/about/#api">API Usage Guide</a>.
390 </p>
391 </section>
392
393 <section>
394 <h2>Share {name}</h2>
395 <p>
396 Help your friends compare {parentSection.name}, and pick
397 privacy-respecting software and services.<br />
398 Share {name} and Awesome Privacy with your network!
399 <div>
400 <SocialShare
401 url={`${site}/${catSlug}/${secSlug}/${slugify(name)}/`}
402 title={`Checkout ${name}! \n`}
403 description={`Compare #${name} and other privacy-respecting ${parentSection.name} at ` +
404 `Awesome-Privacy.xyz, the free and open source list of private software alternatives. ` +
405 `#privacy #opensource #awesomeprivacy by @Lissy_Sykes`}
406 />
407 </div>
408 </p>
409 </section>
410
411 <div class="pagination-navigation">
412 {
413 previous ? (
414 <Button url={`/${catSlug}/${secSlug}/${slugify(previous)}/`}>
415 <span>← Previous</span>
416 <p>{previous}</p>
417 </Button>
418 ) : (
419 <p class="nothing" />
420 )
421 }
422 <a href={`/${catSlug}/${secSlug}/`} class="go-to-category">
423 View {parentSection.name} ({(parentSection.services || []).length})
424 </a>
425 {
426 next && (
427 <Button url={`/${catSlug}/${secSlug}/${slugify(next)}/`}>
428 <span>Next →</span>
429 <p>{next}</p>
430 </Button>
431 )
432 }
433 </div>
434 </main>
435</Layout>
436
437<style lang="scss">
438 main {
439 margin: var(--space-lg) auto;
440 padding: var(--space-md);
441 width: var(--width-container);
442 max-width: var(--width-container-max);
443 position: relative;
444 @media (max-width: 768px) {
445 max-width: 95%;
446 padding: var(--space-sm);
447 margin: 0 auto;
448 }
449 }
450
451 section {
452 margin: var(--space-md) 0 var(--space-2xl) 0;
453 padding: var(--space-md);
454 min-height: 8rem;
455 position: relative;
456 border: var(--border-heavy);
457 box-shadow: var(--shadow-lg);
458 background: var(--surface);
459 }
460
461 p {
462 margin: var(--space-xs) 0 var(--space-sm) 0;
463 }
464
465 h2 {
466 font-size: var(--text-3xl);
467 margin: -2rem 0 var(--space-md) -2rem;
468 box-shadow: var(--shadow-lg);
469 background: var(--accent);
470 color: var(--accent-fg);
471 width: fit-content;
472 padding: var(--space-xs) var(--space-sm);
473 @media (max-width: 768px) {
474 margin: -2rem auto var(--space-lg) auto;
475 }
476 }
477
478 h3 {
479 font-size: var(--text-lg);
480 margin-bottom: 0;
481 }
482
483 pre a {
484 text-decoration: none;
485 color: var(--foreground);
486 code {
487 background: var(--code-bg);
488 padding: 0.2rem 0.4rem;
489 border-radius: var(--curve-sm);
490 font-family: var(--font-code);
491 font-size: var(--text-sm);
492 @media (max-width: 768px) {
493 white-space: break-spaces;
494 }
495 }
496 }
497
498 .social-wrap {
499 display: flex;
500 gap: var(--space-md);
501 flex-wrap: wrap;
502 justify-content: space-between;
503 }
504</style>